

clear all
cap log close

*Graph style
sysdir set PERSONAL "W:\ado"
set scheme kailaScheme


global dummies =  "dpl_5 dpl_4 dpl_3 dpl_2 dpl_0 dpl1 dpl2 dpl3 dpl4 dpl5"
global fe1 = "year"
global fe2 = "time year" 
global fe3 = "baseid time year" 
global fe_full = "baseid time year age_time" 
global cluster = "shnro"



use "${dataout}allmatches_allyears_matchpast5", clear


// restrict to those who work together in last December 
gen new_wp_crime=victim_sykstun_lag==defendant_sykstun_lag & defendant_sykstun_lag!=""

bys match_id1 year_event: ereplace new_wp_crime=max(new_wp_crime)
keep if new_wp_crime==1 


ren shnro defendant_shnro
ren victim_shnro shnro


rename shnro victim_shnro
rename defendant_shnro shnro 



destring suspect_sex, replace 
destring plaintiff_sex, replace 


sort match_id1 year_event time shnro 



bys match_id1 year_event time: ereplace suspect_sex=max(suspect_sex)
bys match_id1 year_event time: ereplace plaintiff_sex=max(plaintiff_sex)



gen mf=(suspect_sex==1 & plaintiff_sex==2 ) 
gen mm=(suspect_sex==1 & plaintiff_sex==1)





sort shnro year_event time 
gen prior_earnings1=realAllEarn if time==-1 
gen prior_earnings2=realAllEarn if time==-2 
gen prior_earnings3=realAllEarn if time==-3

bysort shnro year_event: ereplace  prior_earnings1=mean( prior_earnings1)
bysort shnro year_event: ereplace  prior_earnings2=mean( prior_earnings2)
bysort shnro year_event: ereplace  prior_earnings3=mean( prior_earnings3)

egen prior_earnings=rmean (prior_earnings1 prior_earnings2 prior_earnings3)

gen share_earning=realAllEarn/prior_earnings

sum share_earning, d 
replace share_earning=10 if share_earning>10



gen baseyr=year_event

gen treat= wp_crime==1

gen age_time=age+time



gen treatPost= treat==1 & time>0


* Generate treatment wave indentifier for each individual
egen baseid=group(shnro baseyr)


g perp = 1 
replace match_id1 = match_id1+100000
tempfile perpdata
save `perpdata'

// VICTIMS 


use "${dataout}victim_allmatches_allyears_matchpast5", clear


gen new_wp_crime=victim_sykstun_lag==defendant_sykstun_lag & defendant_sykstun_lag!=""
bys match_id1 year_event: ereplace new_wp_crime=max(new_wp_crime)
keep if new_wp_crime==1 



destring suspect_sex, replace 
destring plaintiff_sex, replace 
sort match_id1 year_event time shnro 
bys match_id1 year_event time: ereplace suspect_sex=max(suspect_sex)
bys match_id1 year_event time: ereplace plaintiff_sex=max(plaintiff_sex)


gen mf=(suspect_sex==1 & plaintiff_sex==2 ) 
gen mm=(suspect_sex==1 & plaintiff_sex==1)


preserve 
	keep shnro defendant_shnro year_event 
	g tmp1 = shnro
	g tmp2 = defendant_shnro
	drop *shnro
	g shnro = tmp2
	g defendant_shnro = tmp1
	drop tmp*
	duplicates drop
	tempfile personid
	save `personid'
restore

merge m:1 shnro defendant_shnro year_event using `personid'
g simulcrime = (_merge==3)
drop _merge 

g crime_type = 0
replace crime_type=0 if suspect_sex==1 & plaintiff_sex==1
replace crime_type=1 if suspect_sex==1 & plaintiff_sex==2
replace crime_type=2 if suspect_sex==2 & plaintiff_sex==1
replace crime_type=3 if suspect_sex==2 & plaintiff_sex==2
lab define wtype 0 "M-M" 1 "M-F" 2 "F-M" 3 "F-F"
lab values crime_type wtype




sort shnro year_event time 
gen prior_earnings1=realAllEarn if time==-1 
gen prior_earnings2=realAllEarn if time==-2 
gen prior_earnings3=realAllEarn if time==-3

bysort shnro year_event: ereplace  prior_earnings1=mean( prior_earnings1)
bysort shnro year_event: ereplace  prior_earnings2=mean( prior_earnings2)
bysort shnro year_event: ereplace  prior_earnings3=mean( prior_earnings3)

egen prior_earnings=rmean (prior_earnings1 prior_earnings2 prior_earnings3)

gen share_earning=realAllEarn/prior_earnings

sum share_earning, d 
replace share_earning=10 if share_earning>10



gen baseyr=year_event

gen treat= wp_crime==1

gen age_time=age+time



gen treatPost= treat==1 & time>0


* Generate treatment wave indentifier for each individual
egen baseid=group(shnro baseyr)


append using `perpdata'
replace perp=0 if missing(perp)



lab var treatPost "Treatment"



est clear
sort shnro year_event time 
bysort shnro year_event: egen post_emp_mean=mean(employed) if time>0
bysort shnro year_event: egen post_earn_mean=mean(realAllEarn) if time>0

bysort shnro year_event: egen post_emp_mean1=mean(employed) if time==1
bysort shnro year_event: egen post_earn_mean1=mean(realAllEarn) if time==1

gen prior_emp=employed if time==-1 
gen prior_earn=realAllEarn if time==-1 
sort shnro year_event time 
bysort shnro year_event: gegen prior_emp=max(prior_emp), replace 
bysort shnro year_event: gegen post_emp_mean=max(post_emp_mean), replace 
bysort shnro year_event: gegen post_emp_mean1=max(post_emp_mean1), replace 

bysort shnro year_event: gegen prior_earn=max(prior_earn), replace 
bysort shnro year_event: gegen post_earn_mean=max(post_earn_mean), replace 
bysort shnro year_event: gegen post_earn_mean1=max(post_earn_mean1), replace 

gen emp_change=(post_emp_mean-prior_emp)/prior_emp
gen earn_change=(post_earn_mean-prior_earn)/prior_earn

gen emp_change1=(post_emp_mean1-prior_emp)/prior_emp
gen earn_change1=(post_earn_mean1-prior_earn)/prior_earn





// Descriptive Employment 
// Figure 2 in QJE
est clear 
cap drop Employment
rename emp_change1 Employment
mean Employment if mf==1 & perp==0 & wp_crime==1
est sto mf_perp0
mean Employment if mf==1 & perp==1 & wp_crime==1
est sto mf_perp1
mean Employment if mm==1 & perp==0 & wp_crime==1
est sto mm_perp0
mean Employment if mm==1 & perp==1 & wp_crime==1
est sto mm_perp1





coefplot mf_perp0 mf_perp1, ///
	vertical yline(0) ytitle("Mean") ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Female") ///
	yscale(r(-0.14 0.02)) ylabel(-0.3(0.05)0) name(mf, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop

coefplot mm_perp0 mm_perp1, ///
	vertical yline(0) ytitle("Mean")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Male") ///
	yscale(r(-0.14 0.02)) ylabel(-0.3(0.05)0) name(mm, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop
	
graph combine mf mm, name(mf_mm, replace) 
graph export "${results}\victim_perp_employment_descriptive1.pdf", replace





preserve 
set scheme s1mono


coefplot mf_perp0 mf_perp1, ///
	vertical yline(0) ytitle("Mean") ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Female") ///
	yscale(r(-0.14 0.02)) ylabel(-0.3(0.05)0) name(mf, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop

coefplot mm_perp0 mm_perp1, ///
	vertical yline(0) ytitle("Mean")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Male") ///
	yscale(r(-0.14 0.02)) ylabel(-0.3(0.05)0) name(mm, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop
	
graph combine mf mm, name(mf_mm, replace) 


graph export "${results}\victim_perp_employment_descriptive1.pdf", replace
graph export "${results}\victim_perp_employment_descriptive1.eps", replace
restore 



 
// Employment DiD 
// Figure 4 (a) in the QJE
reghdfe employed treatPost if mf==1 & perp==0, absorb($fe_full)  cluster($cluster)
est sto mf_perp0
reghdfe employed treatPost if mf==1 & perp==1, absorb($fe_full)  cluster($cluster)
est sto mf_perp1
reghdfe employed treatPost if mm==1 & perp==0, absorb($fe_full)  cluster($cluster)
est sto mm_perp0
reghdfe employed treatPost if mm==1 & perp==1, absorb($fe_full)  cluster($cluster)
est sto mm_perp1


coefplot mf_perp0 mf_perp1, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Female") ///
	yscale(r(-0.14 0.02)) ylabel(-0.14(0.02)0.02) name(mf, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop

coefplot mm_perp0 mm_perp1, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Male") ///
	yscale(r(-0.14 0.02)) ylabel(-0.14(0.02)0.02) name(mm, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop
	
graph combine mf mm, name(mf_mm, replace)
graph export "${results}\victim_perp_employment_DiD.pdf", replace


preserve 
set scheme s1mono

coefplot mf_perp0 mf_perp1, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Female") ///
	yscale(r(-0.14 0.02)) ylabel(-0.14(0.02)0.02) name(mf, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop

coefplot mm_perp0 mm_perp1, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Male") ///
	yscale(r(-0.14 0.02)) ylabel(-0.14(0.02)0.02) name(mm, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop
	
graph combine mf mm, name(mf_mm, replace)
graph export "${results}\victim_perp_employment_DiD.pdf", replace
graph export "${results}\victim_perp_employment_DiD.eps", replace

restore 


// Earnings Share DiD 
// Figure 4 (b) in the QJE 
reghdfe share_earning treatPost if mf==1 & perp==0, absorb($fe_full)  cluster($cluster)
est sto mf_perp0
reghdfe share_earning treatPost if mf==1 & perp==1, absorb($fe_full)  cluster($cluster)
est sto mf_perp1
reghdfe share_earning treatPost if mm==1 & perp==0, absorb($fe_full)  cluster($cluster)
est sto mm_perp0
reghdfe share_earning treatPost if mm==1 & perp==1, absorb($fe_full)  cluster($cluster)
est sto mm_perp1

coefplot mf_perp0 mf_perp1, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Female") ///
	yscale(r(-0.3 0.1)) ylabel(-0.3(0.1)0.1) name(mf, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop

coefplot mm_perp0 mm_perp1, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Male") ///
	yscale(r(-0.3 0.1)) ylabel(-0.3(0.1)0.1) name(mm, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop
	
graph combine mf mm, name(mf_mm, replace)
graph export "${results}\victim_perp_shareEarn_DiD.pdf", replace

preserve 
set scheme s1mono
coefplot mf_perp0 mf_perp1, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Female") ///
	yscale(r(-0.3 0.1)) ylabel(-0.3(0.1)0.1) name(mf, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop

coefplot mm_perp0 mm_perp1, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient")  ///
	legend(order(2 "Victim" 4 "Perp")) subtitle("Male-Male") ///
	yscale(r(-0.3 0.1)) ylabel(-0.3(0.1)0.1) name(mm, replace) ///
	recast(bar) barwidth(0.3) fcolor(*0.8) ciopts(recast(rcap)) citop
	

graph combine mf mm, name(mf_mm, replace)
graph export "${results}\victim_perp_shareEarn_DiD.pdf", replace
graph export "${results}\victim_perp_shareEarn_DiD.eps", replace
restore 

